package com.fenghuajueli.module_user.vip

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.fenghuajueli.libbasecoreui.baseswitch.SwitchKeyUtils
import com.fenghuajueli.module_route.UserModuleRoute
import com.fenghuajueli.module_user.network.repository.TemplateRepository

/**
 * @Author: sz_ijj
 * @Date: 2024-03-26 14:38
 **/
@Interceptor(name = "VipInterceptor", priority = 1)
class VipInterceptor : IInterceptor {
    override fun init(context: Context?) {}

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        if (postcard?.path == UserModuleRoute.USER_OPEN_VIP_ACTIVITY &&
            SwitchKeyUtils.getVipTemplateSwitch() != null &&
            TemplateRepository.initializerState
        ) {
            ARouter.getInstance().build(UserModuleRoute.USER_TEMPLATE_VIP_ACTIVITY).navigation()
            callback?.onInterrupt(null)
        } else {
            callback?.onContinue(postcard)
        }
    }
}